import { useUserStore } from '@/store/user'
let isReloginPrompting = false

export function getReloginStatus(): boolean {
  return isReloginPrompting
}

export function setReloginStatus(value: boolean): void {
  isReloginPrompting = value
}

export async function showReloginModal(): Promise<void> {
  return new Promise((resolve) => {
    uni.showModal({
      title: '提示',
      content: '登录状态已过期，请重新登录',
      showCancel: false,
      confirmText: '确定',
      success() {
        setReloginStatus(false)
        const userStore = useUserStore()
        userStore.removeUserInfo()
        uni.reLaunch({ url: '/pages/login/index' })
        resolve()
      },
      fail() {
        setReloginStatus(false)
        resolve()
      },
    })
  })
}
